//
//  SWV.m
//  ShowWebView
//
//  Created by hjj on 13-3-8.
//  Copyright (c) 2013年 hjj. All rights reserved.
//

#import "Query.h"

@implementation Query
{
    NSMutableDictionary *queryParams;
}
//@synthesize name;
@synthesize value;

-(id)initWithURL:(NSString *) url
{
    self = [super init];
    if (self) {
        queryParams = [[NSMutableDictionary alloc]init];
        NSLog(@"%@:%@",url,[url componentsSeparatedByString:@"&"]);
        NSArray *arr = [NSArray arrayWithArray:[url componentsSeparatedByString:@"?"]];
        if ([arr count]>1) {
        NSString *query = [arr objectAtIndex:1];
        NSArray *components = [query componentsSeparatedByString:@"&"];
        for (NSString *component in components) {
            NSArray *pair = [component componentsSeparatedByString:@"="];
            [queryParams setObject:[[pair objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding]
                            forKey:[pair objectAtIndex:0]];}
        }
    }
    return self;
}
-(NSString *)getValue:(NSString *)name
{
    self.value = [queryParams valueForKey:name];
    return self.value;
}

@end
